
#include "mpLog.h"
#include "mpStringUtils.h"
#include "mpStringUtilsTests.h"

mpStringUtilsTests::mpStringUtilsTests()
{
}

void mpStringUtilsTests::initTestCase(){}
void mpStringUtilsTests::cleanupTestCase(){}

void mpStringUtilsTests::case_upper_lower(){
    //    void stringToUpper(std::string* s);
    //    void stringToLower(std::string* s);
    //    std::string stringToUpper_copy(const std::string& s);
    //    std::string stringToLower_copy(const std::string& s);
#ifdef TEST_STRATEGY_COMPLETED

    std::string str = "abcABCefgEFG";
    std::string upper = "ABCABCEFGEFG";
    std::string lower = "abcabcefgefg";


    std::string stringToUpper_copy = MP::StringUtils::stringToUpper_copy(str);
    std::string stringToLower_copy = MP::StringUtils::stringToLower_copy(str);

    QVERIFY2(stringToUpper_copy == upper,"case_upper_lower 1");
    QVERIFY2(stringToLower_copy == lower,"case_upper_lower 2");

    MP::StringUtils::stringToUpper(&str);
    QVERIFY2(str == upper,"case_upper_lower 3");

    MP::StringUtils::stringToLower(&str);
    QVERIFY2(str == lower,"case_upper_lower 4");


#endif
}

void mpStringUtilsTests::case_trim(){
#ifdef TEST_STRATEGY_COMPLETED

//    std::string trim_copy(const std::string& s);
//    std::string trim_copy(const std::string& s, const std::string& trim_value);

    std::string trim1_1 = "   abc ";
    std::string trim1_2 = "   abc";
    std::string trim1_3 = "abc";
    std::string trim1_4 = "abc";

    QVERIFY2(MP::StringUtils::trim_copy(trim1_1) == "abc","case_trim 1");
    QVERIFY2(MP::StringUtils::trim_copy(trim1_2) == "abc","case_trim 2");
    QVERIFY2(MP::StringUtils::trim_copy(trim1_3) == "abc","case_trim 3");
    QVERIFY2(MP::StringUtils::trim_copy(trim1_4) == "abc","case_trim 4");

    std::string trim2_1 = "****abcefgh*";
    std::string trim2_2 = "****abcefgh***";
    std::string trim2_3 = "abcefgh*****";
    std::string sp = "**";

    QVERIFY2(MP::StringUtils::trim_copy(trim2_1,sp) == "abcefgh*","case_trim 5");
    QVERIFY2(MP::StringUtils::trim_copy(trim2_2,sp) == "abcefgh*","case_trim 6");
    QVERIFY2(MP::StringUtils::trim_copy(trim2_3,sp) == "abcefgh*","case_trim 7");

#endif
}

void mpStringUtilsTests::case_join(){
#ifdef TEST_STRATEGY_COMPLETED

//    std::string joinStrings(const std::vector<std::string>& str_vec,
//                            const std::string& delimiter);

    std::string delimiter = "**";
    std::vector<std::string> str_vec;
    str_vec.push_back("小刚");
    str_vec.push_back("阿明");
    str_vec.push_back("大强");

    QVERIFY2(MP::StringUtils::joinStrings(str_vec,delimiter) == "小刚**阿明**大强","case_join");

#endif
}

void mpStringUtilsTests::case_split(){
#ifdef TEST_STRATEGY_COMPLETED

//    void splitString(const std::string& str,
//                     char delim,
//                     std::vector<std::string> & vec);
//    void splitString(const std::string& str,
//                     const std::string& sep,
//                     std::vector<std::string> & vec);

    char delim = '-';
    std::string str1 = "小刚--阿明-大强";
    std::vector<std::string> vec1;

    MP::StringUtils::splitString(str1,delim,vec1);
    QVERIFY2(vec1.size() == 4,"case_split 1");
    QVERIFY2(vec1[1] == "","case_split 2");
    QVERIFY2(vec1[2] == "阿明","case_split 3");

    str1 = "小刚----阿明-大强";
    std::vector<std::string> vec2;
    std::string sep = "--";
    MP::StringUtils::splitString(str1,sep,vec2);

    QVERIFY2(vec2.size() == 3,"case_split 4");
    QVERIFY2(vec2[1] == "","case_split 5");

#endif
}

void mpStringUtilsTests::case_startwith_endwith(){
#ifdef TEST_STRATEGY_COMPLETED

//    bool stringStartsWith(const std::string& str,
//                          const std::string& prefix);
//    bool stringEndsWith(const std::string& str,
//                        const std::string& suffix);

//    bool stringStartsWithIgnoreCase(const std::string& str,
//                                    const std::string& prefix);
//    bool stringEndsWithIgnoreCase(const std::string& str,
//                                  const std::string& suffix);


    std::string str = "Abcdefgh";
    QVERIFY2(MP::StringUtils::stringStartsWith(str,"Ab"),"case_startwith_endwith 1");
    QVERIFY2(!MP::StringUtils::stringStartsWith(str,"ab"),"case_startwith_endwith 2");
    QVERIFY2(MP::StringUtils::stringEndsWith(str,"gh"),"case_startwith_endwith 3");
    QVERIFY2(!MP::StringUtils::stringEndsWith(str,"gH"),"case_startwith_endwith 4");

    QVERIFY2(MP::StringUtils::stringStartsWithIgnoreCase(str,"Ab"),"case_startwith_endwith 5");
    QVERIFY2(MP::StringUtils::stringStartsWithIgnoreCase(str,"ab"),"case_startwith_endwith 6");
    QVERIFY2(MP::StringUtils::stringEndsWithIgnoreCase(str,"gh"),"case_startwith_endwith 7");
    QVERIFY2(MP::StringUtils::stringEndsWithIgnoreCase(str,"gH"),"case_startwith_endwith 8");

#endif
}
